package com.neusoft.yuejian_6.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;


import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.adapter.ContestListAdapter;
import com.neusoft.yuejian_6.javabean.Contest;
import com.neusoft.yuejian_6.model.ContestModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class HomeZuijinFragment extends Fragment {

    private RecyclerView recyclerView;
    private List mDataList;
    private View view=null;


    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view=inflater.inflate(R.layout.fragment_zuijin, container, false);

        initViews();
        initEvents();
        initData();
        return view;

    }
    private void initViews(){

        recyclerView= (RecyclerView)view.findViewById(R.id.rv_zuijin);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }

    private void  initEvents(){

    }

    private void initData()
    {

        ContestModel contestModel = new ContestModel();
        Call call = contestModel.Contests();
        call.enqueue(new Callback<List<Contest>>() {
            @Override
            public void onResponse(Call<List<Contest>> call, Response<List<Contest>> response) {
                //mDataList= (List) response.body();
                List<Contest> data=response.body();
                System.out.printf("data");
                recyclerView.setAdapter(new ContestListAdapter(getActivity(),data));
                //recyclerView.setAdapter(new ContestListAdapter(getContext(),data));
            }

            @Override
            public void onFailure(Call<List<Contest>> call, Throwable t) {
                Toast.makeText(getContext(), "fail", Toast.LENGTH_SHORT).show();
            }
        });

    }
}

